<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>${sysName}</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${resRoot}/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${resRoot}/layui/admin/admin.css" media="all" />
	<link id="layuicss-layer" rel="stylesheet" href="${resRoot}/layui/css/modules/layer/default/layer.css" media="all">
	<script type="text/javascript" src="${resRoot}/ckeditor/ckeditor.js"></script>
	<script type="text/javascript" src="${resRoot}/ckfinder/ckfinder.js"></script>
</head>
<body>
<div class="layui-fluid">   
          <div class="layui-card">
          <div class="layui-form layui-card-header layuiadmin-card-header-auto"> 
 
<form class="layui-form" action="#" style="margin-top: 20px;" >
<input type="hidden" id="id" value="<#if bannerDTO??>${bannerDTO.id}<#else></#if>" >
  <div class="layui-form-item">
    <label class="layui-form-label">标题</label>
    <div class="layui-input-inline">
	      <input type="text" name="name" id="name" value="<#if bannerDTO?? && bannerDTO.name?? >${bannerDTO.name! }</#if>"  autocomplete="off" placeholder="请输入标题" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入标题</div>
  </div>
  
  <!-- 图片 -->
  	<div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">图片url</label>
      <div class="layui-input-inline">
      <div class="site-demo-upload">
		  <img id="picUrl_img" imgName="<#if bannerDTO?? && bannerDTO.picUrl?? >${bannerDTO.picUrl!}</#if>" src="<#if bannerDTO?? && bannerDTO.picUrl?? >${picUrlHost}${bannerDTO.picUrl!}</#if>" style="max-width:200px;max-height:200px;">
		  <button type="button" class="layui-btn" id="test1">
		  <i class="layui-icon"></i>上传图片url
		</button><input class="layui-upload-file" type="file" accept="images" name="fileField" id="fileField">
		</div>
      </div>
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">排序</label>
    <div class="layui-input-inline">
	      <input type="number" name="sort" id="sort" value="<#if bannerDTO?? && bannerDTO.sort?? >${bannerDTO.sort!}</#if>"  autocomplete="off" placeholder="请输入排序" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入排序</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">外链</label>
    <div class="layui-input-inline">
	      <input type="text" name="url" id="url" value="<#if bannerDTO?? && bannerDTO.url?? >${bannerDTO.url! }</#if>"  autocomplete="off" placeholder="请输入外链" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入外链</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">是否展示</label>
    <div class="layui-input-inline">
	      <select name="isShow" id="isShow" lay-verify="required">
        <option value="1" <#if bannerDTO?? && bannerDTO.isShow?? && bannerDTO.isShow=="1"> selected="selected"</#if>>展示</option>
        <option value="0" <#if bannerDTO?? && bannerDTO.isShow?? && bannerDTO.isShow=="0"> selected="selected"</#if>>不展示</option>
      </select>
    </div>
    <div class="layui-form-mid layui-word-aux">请输入是否展示</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">类型</label>
    <div class="layui-input-inline">
	      <select name="type" id="type" lay-verify="required">
	        <option value="0" <#if bannerDTO?? && bannerDTO.type?? && bannerDTO.type=="0"> selected="selected"</#if>>客户端</option>
	      </select>
    </div>
    <div class="layui-form-mid layui-word-aux">请输入类型</div>
  </div>
  

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" id="submitBtn"  lay-submit=""  type="button">立即提交</button>
      <button type="button" class="layui-btn layui-btn-primary" onclick="backList();" >返回</button>
    </div>
  </div>
</form>
</div>
  </div>
  </div>
<script src="${resRoot}/layui/layui.js" charset="utf-8"></script>
<script src="${resRoot}/js/jquery.min.js?v=2.1.4"></script>
<script type="text/javascript" src="${resRoot}/js/ajaxfileupload.js"></script>
<script>
function backList() {
	layer.closeAll("iframe");
    //刷新父页面
    parent.location.reload();
}

function removeImg(id) {
	layer.confirm('您是确认删除/查看该图片吗？', {
		  btn: ['确认','查看'] //按钮
		}, function(){
			$("#" + id).attr("src", "");
			layer.msg('已删除！');
		}, function(){
			window.open($("#" + id).attr("src"));
		  //layer.msg('已取消！');
		});
}
layui.use(['form', 'layedit', 'laydate', 'upload'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  
  var upload = layui.upload;
		var uploadInst1 = upload.render({
		    elem: '#test1' //绑定元素
		    ,url: '${base}/uploadImage' //上传接口
		    ,done: function(res){
		    if(res != "") {
	    		var obj = res;
				$("#picUrl_img").attr("src", '${picUrlHost}' + obj.imageUrl);
				$("#picUrl_img").attr("imgName", obj.imageUrl);
	    		
			}
		      //上传完毕回调
		    }
		    ,error: function(){
		      //请求异常回调
		    }
		  });

  
  
	
  
  //自定义验证规则
  form.verify({
    title: function(value){
      if(value.length == 0){
        return '参数不能为空';
      }
    }
    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });
  
  
  
  $("#submitBtn").click(function(){
		var name=$("#name").val();
	  var id = $("#id").val();
	  var picUrl=$("#picUrl_img").attr("imgName");
		var sort=$("#sort").val();
		var url=$("#url").val();
		var isShow=$("#isShow").val();
		var type=$("#type").val();
		var flag = true;
		if(name=="" || name ==null || name =="undefined") {
			layer.alert("请输入标题！");
		      flag = false;
		      return false;
		}
		if(picUrl=="" || picUrl ==null || picUrl =="undefined") {
			layer.alert("请输入图片url！");
		      flag = false;
		      return false;
		}
		if(sort=="" || sort ==null || sort =="undefined") {
			layer.alert("请输入排序！");
		      flag = false;
		      return false;
		}
		if(isShow=="" || isShow ==null || isShow =="undefined") {
			layer.alert("请输入是否展示！");
		      flag = false;
		      return false;
		}
		if(type=="" || type ==null || type =="undefined") {
			layer.alert("请输入类型！");
		      flag = false;
		      return false;
		}
		if(flag) {
			$.ajax({
				type : "post",
				url : "${base}/sys/banner/save",
				data : {
					name : name,
					picUrl : picUrl,
					sort : sort,
					url : url,
					isShow : isShow,
					type : type,
					id : id					
					},
				dataType : "json",
				async : false,
				success : function(data) {
					if(data.message == 2) {
							layer.msg('请完善数据！');   
						} else if(data.message == 1) {
							layer.msg('保存成功！', {
							  icon: 1,
							  time: 2000 //2秒关闭（如果不配置，默认是3秒）
							}, function(){
								backList();
							});   
						} else {
							layer.msg('系统繁忙！'); 
						}
				}
			}); 
		}
	});
  
  
});

layui.use('upload', function(){
	  
});  
</script>
</body>
</html>